<template>
	<div style="padding:0px;">
		<el-form :model="dialogForm" ref="dialogForm" :rules="rules" :label-width="formLabelWidth">
		<el-card class="box-card">
		  <div slot="header" class="clearfix">
		    <span style="line-height: 30px;">审核车源</span>
		  </div>
		  <div  class="text item">
			
			  	<el-form-item label="汽车品牌" >
			      <el-input v-model="dialogForm.carBrandName" auto-complete="off" disabled></el-input>
			    </el-form-item>
			    <el-form-item label="汽车子品牌" >
			      <el-input v-model="dialogForm.carSubBrandName" auto-complete="off" disabled></el-input>
			    </el-form-item>
			    <el-form-item label="汽车车系" >
			      <el-input v-model="dialogForm.carSeriesName" auto-complete="off" disabled></el-input>
			    </el-form-item>
			    <el-form-item label="汽车车型" >
			      <el-input v-model="dialogForm.carTypeName" auto-complete="off" disabled></el-input>
			    </el-form-item>
			    <el-form-item label="外观颜色" >
			      <el-input v-model="dialogForm.color" auto-complete="off" disabled></el-input>
			    </el-form-item>
			    <el-form-item label="内饰颜色" >
			      <el-input v-model="dialogForm.interiorColor" auto-complete="off" disabled></el-input>
			    </el-form-item>
			    <el-form-item label="是否现车" >
			      <el-input :value='dialogForm.carInStock?"是":"否"' auto-complete="off" disabled></el-input>
			    </el-form-item>
			    <el-form-item label="指导价(元)" >
			      <el-input v-model="dialogForm.carTypePrice" auto-complete="off" disabled></el-input>
			    </el-form-item>
			    <el-form-item label="报价(元)" >
			      <el-input v-model="dialogForm.price" auto-complete="off" disabled></el-input>
			    </el-form-item>
			    <el-form-item label="需收定金(元)" >
			      <el-input v-model="dialogForm.deposit" auto-complete="off" disabled></el-input>
			    </el-form-item>
			    <el-form-item label="手续" >
			      <el-input v-model="dialogForm.procedureName" auto-complete="off" disabled></el-input>
			    </el-form-item>
			    <el-form-item label="销售区域"  >
			      <el-input type="textarea" :rows=3 v-model="dialogForm.salesArea" auto-complete="off" disabled></el-input>
			    </el-form-item>
			    <el-form-item label="车辆所在地"  >
			      <el-input type="textarea" :rows=3 v-model="dialogForm.curLocation" auto-complete="off" disabled></el-input>
			    </el-form-item>
			    <el-form-item label="车源有效期" >
			      <el-input v-model="dialogForm.durationName" auto-complete="off" disabled></el-input>
			    </el-form-item>
			    <el-form-item label="图片信息" >
				  <qiniu :qiniuImage="qiniuImage"  :id="qiniuImage.id" :canDelete="false"></qiniu>
				    </el-form-item>
			    <el-form-item label="备注"  prop="qczjg">
			      <el-input type="textarea" :rows=3 v-model="dialogForm.remark" auto-complete="off" disabled></el-input>
			    </el-form-item>
			  
			</div>
		</el-card>
		<el-card v-if="dialogSendData.isAdd" class="box-card" style="margin-top:15px;">
		  <div slot="header" class="clearfix">
		    <span style="line-height: 30px;">确认信息</span>
		  </div>
		  <div  class="text item">
			  	<el-form-item label="审核信息"  prop="status">
			        <el-radio-group v-model="dialogForm.status">
				      <el-radio :label="4" > 通过 </el-radio>
  				      <el-radio :label="3" > 不通过 </el-radio>
				    </el-radio-group>
			    </el-form-item>
			     <el-form-item label="审核备注"  prop="reviewRemark" :rules="this.dialogForm.status==3?rules.priceRemark:[{ required: false, message: '请填写审核备注', trigger: 'blur' }]">
			      <el-input type="textarea" :rows=3 v-model="dialogForm.reviewRemark" :maxlength=100 auto-complete="off"></el-input>
			    </el-form-item>
          </div>
		</el-card>
		</el-form>
		<div  style="text-align:right;margin-top:15px;">
			 <el-button @click="returnBack">返 回</el-button>
			 <el-button v-if="dialogSendData.isAdd" type="primary" @click="submitConfirmForm('dialogForm')">提 交</el-button>
		</div>
	</div>
</template>
<script>
    import agentHttp from '@/utils/agentHttp.js'
    import qiniu from '@/views/qiniu/upload';
	export default{
		components:{
			qiniu
		},
		created(){
   			if(this.dialogSendData.id!==""){
	      		this.selectData();//修改      	    
	      	}else{	      		
	      		console.log('新增')
	      	}
        },
		props:['dialogSendData','tableData'],
		data(){
			return{
				formLabelWidth:'170px',
				//弹窗或者查看页面信息
		        dialogForm:{
		        },
		        //验证规则：
			    rules: {
			        status: [
			          { required: true, message: '请选择选择确认与否', trigger: 'change',type:'number' }
			        ],
			        reviewRemark:[
			          {required: true, message: '请填写备注信息', trigger: 'blur'}
			        ]
			    },
			    qiniuImage:{
			        id:"qiniuImage", //图片预览的id   
			        image_uri:[]    //图片上传的列表  只含有url地址
			    }
			}
		},methods:{
			returnBack(){
				this.dialogSendData.dialogFormVisible=false;
			},
			submitConfirmForm(formName){				
                this.$refs[formName].validate((valid) => {
		          if (valid) {
		          	if(this.dialogSendData.id===""){
		          		//添加
		          	}else{		          		
		          		this.editData();//修改
		          	}
		          	
		          } else {
		            this.$nextTick(()=>{
			          	this.$message.warning(document.getElementsByClassName('el-form-item__error')[0].innerText);
			            return false;
		            })
		          }
		        });
			},
			editData(){
		        agentHttp.putJson('adminApi/admin/car_source/put_validated',this.dialogForm).then((data)=>{
		            if(data.success){  
		            	this.$emit('refreshSeachData', null);
		            	this.$message.success(data.data||"修改成功");
		            	setTimeout(()=>{
		          		this.dialogSendData.dialogFormVisible=false;
		          	  },500)
		          	
		            } 
		        }) 
		    },
		    selectData(){
		        agentHttp.get('adminApi/admin/car_source/select_source/'+this.dialogSendData.id).then((data)=>{	
		            if(data.success){
		            	this.dialogForm=data.data;
		            	this.dialogForm.picUrl?this.qiniuImage.image_uri= this.dialogForm.picUrl.split(',').notempty():[];
		            	if (this.dialogSendData.isAdd&&data.data.status==2) {
                         this.dialogForm.status=4;
		            	}
		            	
		            } 
		        }) 
		    }
		    
		}
	};
</script>